package com.example.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.*;
import com.example.mapper.CollectMapper;
import com.example.service.CollectService;
import com.example.utils.PageResult;
import com.example.vo.CollectVO;
import com.example.vo.VideoDatabaseVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Resource
    private CollectMapper collectMapper;

    /**
     * 根据id用户id查找某个用户的收藏表单
     * @param userId
     * @return
     */
    @Override
    public List<CollectVO> selectCollectList(Integer userId) {
        return collectMapper.selectCollectList(userId);
    }


    /**
     * 查看视频库
     * @param majorId
     * @return
     */
    @Override
    public List<VideoDatabaseVO> selectVideoDatabase(Integer majorId) {
        return collectMapper.selectVideoDatabase(majorId);
    }

    /**
     * 收藏课程
     * @param courseId
     * @return
     */
    @Override
    public Integer collectCourse(Integer courseId) {
        return collectMapper.collectCourse(courseId);
    }

    @Override
    public List<CollectVO> selectAll() {
        return collectMapper.selectAll();
    }

    /**
     * 修改收藏信息
     * @param nickName
     * @param majorName
     * @param unitName
     * @param courseName
     * @param picUrl
     * @return
     */
    @Override
    public Integer modifyCollect(Integer id,String nickName, String majorName, String unitName, String courseName, String picUrl) {
        return collectMapper.modifyCollect(id,nickName,majorName,unitName,courseName,picUrl);
    }

    /**
     * 后端模糊查询
     * @param courseName
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<CollectVO> selectCollectPage(String courseName,Integer page,Integer limit) {
        return collectMapper.selectCollectPage(courseName,page,limit);
    }

    @Override
    public PageResult<List<CollectVO>> queryUserByPage(String courseName, Integer page, Integer limit) {
        PageResult<List<CollectVO>> pageResult = new PageResult<>();
        //启动分页
        PageHelper.startPage(page,limit,true);
        List<CollectVO> collectVOList = collectMapper.selectCollectPage(courseName,page,limit);

        PageInfo<CollectVO> pageInfo = new PageInfo<>(collectVOList);
        pageResult.setPages(pageInfo.getPages());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setList(pageInfo.getList());
        return pageResult;
    }

    /**
     * 假删除
     * @param id
     * @return
     */
    @Override
    public Integer deleteCollect(Integer id) {
        return collectMapper.deleteCollect(id);
    }

    @Override
    public List<Major> selectMajorById() {
        return collectMapper.selectMajorById();
    }

    @Override
    public List<User> selectUser() {
        return collectMapper.selectUser();
    }

    @Override
    public List<Unit> selectUnitById(Integer majorId) {
        return collectMapper.selectUnitById(majorId);
    }

    @Override
    public List<Course> selectCourseById(Integer unitId) {
        return collectMapper.selectCourseById(unitId);
    }

    /**
     * 级联查询
     * @param majorId
     * @param unitId
     * @param courseId
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public PageResult<List<CollectVO>> selectByCourseId(Integer majorId,Integer unitId,Integer courseId,Integer userId,Integer page,Integer limit) {
        PageResult<List<CollectVO>> pageResult = new PageResult<>();
        //启动分页
        PageHelper.startPage(page,limit,true);
        List<CollectVO> collectVOList = collectMapper.selectByCourseId(majorId,unitId,courseId,userId,page,limit);

        PageInfo<CollectVO> pageInfo = new PageInfo<>(collectVOList);
        pageResult.setPages(pageInfo.getPages());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setList(pageInfo.getList());
        return  pageResult;
    }

    @Override
    public List<Unit> selectAllUnit() {
        return collectMapper.selectAllUnit();
    }

    @Override
    public List<Course> selectAllCourse() {
        return collectMapper.selectAllCourse();
    }

}
